package UILayer;
import CtrLayer.StaffCtr;

/**
 * Write a description of class StaffUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class StaffUI extends InOut
{
    // instance variables - replace the example below with your own
    private static StaffCtr staffCtr = new StaffCtr();
    private static int idS = 1000;

    /**
     * Constructor for objects of class StaffUI
     */
    public StaffUI()
    {
        // initialise instance variables
        
    }

    public void staffMenu()
    {
        String[] staffMenu = {"Staff MENU", "Create employee", "Create Manager", "Retrieve staff member's information", "Update staff member's data", "Delete staff member"};
        printMenu(staffMenu);
    }
    
    public void start()
    {
        boolean exit = false;
        while(!exit)
        {
            erase(1);
            staffMenu();
            int choice = inputInt("Choose: ");
            erase(1);
            switch(choice)
            {
                case 1 : {createEmployee();}break;
                case 2 : {createManager();}break;
                case 3 : {getStaff();}break;
                case 4 : {updateStaff();}break;
                case 5 : {deleteStaff();}break;
                case 6 : {exit=true;}break;


                default : {}break;
            }
            if(choice>=1 && choice<=5 && choice!=4) waitK();
        }
    }
    
    public void createEmployee()
    {
        idS++;
        String n = inputString("Enter employee's name: ");
        String a = inputString("Enter employee's address: ");
        String pc = inputString("Enter employee's postal code: ");
        String ph = inputString("Enter employee's phone number: ");
        String e = inputString("Enter employee's e-mail address: ");
        String u = inputString("Set employee's username: ");
        String ps = inputString("Set employee's password: ");
        staffCtr.createEmployee(idS, n, a, pc, ph, e, u, ps);
        System.out.println("Employee with ID: " + idS + " created.");
    }
    
    public void createManager()
    {
        idS++;
        String n = inputString("Enter manager's name: ");
        String a = inputString("Enter manager's address: ");
        String pc = inputString("Enter manager's postal code: ");
        String ph = inputString("Enter manager's phone number: ");
        String e = inputString("Enter manager's e-mail address: ");
        String u = inputString("Set manager's username: ");
        String ps = inputString("Set manager's password: ");
        staffCtr.createManager(idS, n, a, pc, ph, e, u, ps);
        System.out.println("Manager with ID: " + idS + " created.");
    }
    
    public void getStaff()
    {
        int id = inputInt("Staff member's ID: ");
        try{
            print("######## STAFF INFORMATION ########");
            print("ID: " + staffCtr.getStaffById(id).getId());
            print("Name: " + staffCtr.getStaffById(id).getName());
            print("Address: " + staffCtr.getStaffById(id).getAddress());
            print("Postal Code: " + staffCtr.getStaffById(id).getPostCode());
            print("Phone number: " + staffCtr.getStaffById(id).getPhone());
            print("E-mail address: " + staffCtr.getStaffById(id).getEmail());
        }
        catch(Exception e){print("No staff member with given id");}
    }
    
    public void updateStaffMenu(int id)
    {
        String[] updateStMenu = {"Update Staff member with ID "+id, "Update name", "Update address", "Update postal code", "Update phone number", "Update email", "Change username", "Change password"};
        printMenu(updateStMenu);
    }
    
    public void updateStaff()
    {
        int id = inputInt("Staff member's ID: ");
        if(id==-1) print("-> Invalid staff's ID.");
        else{
            boolean exit = false;
            while(!exit){
                erase(1);
                updateStaffMenu(id);
                int choice = inputInt("Choose: ");
                
                if(choice<1 || choice > 7) {exit = true;}
                else{
                    String upInf = "New value: ";
                    updateStaff(id, choice, upInf);
                    waitK();
                }
            }
        }
        }
    
    public void updateStaff(int id, int opt, String upInf)
    {
        String newValue = inputString(upInf);
        if(staffCtr.updateStaff(id, newValue, opt)) print(" -> Staff member was successfully updated.");
        else print(" -> Staff member with id "+id+" does not exist.");
    }
    
    public void deleteStaff()
    {
        int id = inputInt("Staff member's ID: ");
        if(staffCtr.deleteStaff(id)) print(" -> Staff member was successfully deleted.");
        else print(" -> Staff member with id "+id+" does not exist.");
    }
}
